#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2022/8/14 21:49
import sys, os
from infrastructure.constant.Image_size_enum import ImageSizeEnum

# 解决pyinstaller打包python程序可执行文件路径问题
if getattr(sys, 'frozen', False):  # 判断是exe还是.py程序
    # __icon_path = os.path.dirname(sys.executable)  # exe程序路径
    __icon_path = sys._MEIPASS  # exe程序路径
elif __file__:
    __icon_path = os.path.dirname(__file__)  # .py程序路径

def get_favicon_path(key:str, size:ImageSizeEnum=ImageSizeEnum.s16X16):
    key = key if key is not None and len(key) > 0 else "default"
    size = size if size is not None else ImageSizeEnum.s16X16
    icon_path = os.path.join(__icon_path, f"{key}_{size.name}.ico")
    if os.path.exists(icon_path):
        return icon_path
    else:
        return None